#ifndef SSX_VEC_INCLUDED
#define SSX_VEC_INCLUDED
#include <unistd.h>
#include <iostream>
template<typename Object>
class SsxVector
{
public:
    SsxVector(int s = 0){
        objects = new Object[s + SPACE_CAPACITY];
        thesize = s;
        capacity = s + SPACE_CAPACITY;
    }

    SsxVector(const SsxVector & rhs)
    {
        *this=rhs;

    }

    const SsxVector& operator=(const SsxVector & rhs)
    {
        delete objects;
        int rhsCapacity = rhs.capacity;
        int rhsSize = rhs.thesize;
        objects = new Object[rhsCapacity];
        for(int i = 0; i < rhsSize; ++i)
        {
            objects[i] = rhs.objects[i];
        }
        thesize = rhsSize;
        capacity = rhsCapacity;

        return *this;

    }


    Object & operator[](int index)
    {

        return objects[index];
    }


    ~SsxVector()
    {
        delete objects;
        objects = NULL;
    }


    void reserve(int cap)
    {
        if(cap > capacity)
        {
            cap = 2 * cap + 1;
            Object *  oldObjects = objects;
            objects = new Object[cap];
            for(int i = 0; i < thesize ; ++i)
            {
                objects[i] = oldObjects[i];

            }
            delete oldObjects;
            capacity = cap;
        }

    }


    void resize(int newsize)
    {

        if(newsize > capacity )
            reserve(newsize);
        thesize = newsize;
    }

    void pushBack(const Object & ob)
    {

        if( (thesize + 1) == capacity )
        {
            std::cout << "reserve" << std::endl;
            reserve(2 * thesize);

        }
        objects[thesize++] = ob;

    }


    int vecSize()
    {

        return thesize;
    }

    int vecCapacity()
    {
        return capacity;
    }





    /*
        iterator of vector
    */
    class SsxIterator{
    public:
        SsxIterator():node(NULL){
        }



        Object & operator*()
        {
            return *node;
        }

        SsxIterator & operator++()
        {
            std::cout << "++node" << std::endl;
            ++node;
            return *this;
        }

        SsxIterator  operator++(int)
        {
            SsxIterator oldit(*this);
            ++*this;
            return oldit;
        }
/*
        SsxIterator & begin()
        {
            node = objects;
            return *this;
        }

        SsxIterator & end()
        {
            node = &objects[thesize];
            return *this;
        }
*/
    protected:
        friend class SsxVector;

        Object * node;


    };


    SsxIterator  vecBegin()
    {
        SsxIterator itr;
        itr.node = objects;
        return itr;
    }

    SsxIterator vecEnd()
    {
        SsxIterator itr;
        itr.node = &objects[thesize];
    }

    enum{SPACE_CAPACITY = 6};

private:
    int thesize;
    int capacity;
    Object * objects;
    friend class SsxIterator;

};



#endif // 3_4VECTOR_H_INCLUDED
